package com.jlrdb.service;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.jlrdb.DAO.RadioBroadcastDAO;
import com.jlrdb.DAO.RadioBroadcastDAOImpl;
import com.jlrdb.model.AnalogRadioBroadcast;
import com.jlrdb.model.AnalogRadioBroadcasts;
import com.jlrdb.model.DigitalRadioBroadcast;
import com.jlrdb.model.DigitalRadioBroadcasts;

public class RadioBroadcastService {
	RadioBroadcastDAO radioBroadcastDAO = new RadioBroadcastDAOImpl();

	public int addRadioBroadcastDigital(DigitalRadioBroadcast digitalRadioBroadcast) {
		int result = radioBroadcastDAO.addRadioBroadcastDigital(digitalRadioBroadcast);
		return result;
	}

	public DigitalRadioBroadcasts viewRadioBroadcastsDigital(String criteria, String value) {
		DigitalRadioBroadcasts digitalRadioBroadcasts = new DigitalRadioBroadcasts();
		digitalRadioBroadcasts = radioBroadcastDAO.viewRadioBroadcastsDigital(criteria, value);
		return digitalRadioBroadcasts;
	}

	public DigitalRadioBroadcast checkEmptyValuesDigital(DigitalRadioBroadcast digitalRadioBroadcast) {
		if (digitalRadioBroadcast.getAnalog_radio().length() == 0)
			digitalRadioBroadcast.setAnalog_radio("Not Known");
		if (digitalRadioBroadcast.getDigitization_Status().length() == 0)
			digitalRadioBroadcast.setDigitization_Status("Not Known");
		if (digitalRadioBroadcast.getDigital_Radio_Family().length() == 0)
			digitalRadioBroadcast.setDigital_Radio_Family("Not Known");
		if (digitalRadioBroadcast.getStandard().length() == 0)
			digitalRadioBroadcast.setStandard("Not Known");
		if (digitalRadioBroadcast.getTransmission_Status().length() == 0)
			digitalRadioBroadcast.setTransmission_Status("Not Known");
		if (digitalRadioBroadcast.getCoverage().length() == 0)
			digitalRadioBroadcast.setCoverage("Not Known");
		if (digitalRadioBroadcast.getStart_Date().length() == 0)
			digitalRadioBroadcast.setStart_Date("Not Known");
		if (digitalRadioBroadcast.getStop_date().length() == 0)
			digitalRadioBroadcast.setStop_date("Not Known");
		if (digitalRadioBroadcast.getFrequency_Spectrum().length() == 0)
			digitalRadioBroadcast.setFrequency_Spectrum("Not Known");
		if (digitalRadioBroadcast.getMajor_Players().length() == 0)
			digitalRadioBroadcast.setMajor_Players("Not Known");
		if (digitalRadioBroadcast.getDigital_Radio_Overall_coverage().length() == 0)
			digitalRadioBroadcast.setDigital_Radio_Overall_coverage("Not Known");
		if (digitalRadioBroadcast.getMultiPlex().length() == 0)
			digitalRadioBroadcast.setMultiPlex("Not Known");
		if (digitalRadioBroadcast.getASO_Start_Date().length() == 0)
			digitalRadioBroadcast.setASO_Start_Date("Not Known");
		if (digitalRadioBroadcast.getASO_End_Date().length() == 0)
			digitalRadioBroadcast.setASO_End_Date("Not Known");
		if (digitalRadioBroadcast.getRegulatory_authority().length() == 0)
			digitalRadioBroadcast.setRegulatory_authority("Not Known");
		if (digitalRadioBroadcast.getNotes().length() == 0)
			digitalRadioBroadcast.setNotes("-");
		if (digitalRadioBroadcast.getSource().length() == 0)
			digitalRadioBroadcast.setSource("-");
		if (digitalRadioBroadcast.getLast_Update_Date() == null)
		{
			DateFormat df = new SimpleDateFormat("dd/MM/yy");
			String formattedDate = df.format(new Date());
			digitalRadioBroadcast.setLast_Update_Date(formattedDate);
		}
		return digitalRadioBroadcast;
	}

	public DigitalRadioBroadcast getThisBroadcastDigital(long broadcastId) {
		DigitalRadioBroadcast digitalRadioBroadcast = new DigitalRadioBroadcast();
		digitalRadioBroadcast = radioBroadcastDAO.getThisBroadcastDigital(broadcastId);
		return digitalRadioBroadcast;
	}

	public int updateRadioBroadcastDigital(DigitalRadioBroadcast digitalRadioBroadcast, long broadcastId) {
		int result = radioBroadcastDAO.updateRadioBroadcastDigital(digitalRadioBroadcast, broadcastId);
		return result;
	}

	public AnalogRadioBroadcast checkEmptyValuesAnalog(AnalogRadioBroadcast analogRadioBroadcast) {
		if (analogRadioBroadcast.getNotes_Remarks().length() == 0)
			analogRadioBroadcast.setNotes_Remarks("-");
		if (analogRadioBroadcast.getMajor_Players().length() == 0)
			analogRadioBroadcast.setMajor_Players("Not Known");
		if (analogRadioBroadcast.getLast_Date_Updated() == null)
		{
			DateFormat df = new SimpleDateFormat("dd/MM/yy");
			String formattedDate = df.format(new Date());
			analogRadioBroadcast.setLast_Date_Updated(formattedDate);
		}
		return analogRadioBroadcast;
	}

	public int addRadioBroadcastAnalog(AnalogRadioBroadcast analogRadioBroadcast) {
		int result = radioBroadcastDAO.addRadioBroadcastAnalog(analogRadioBroadcast);
		return result;
	}

	public AnalogRadioBroadcasts viewRadioBroadcastsAnalog(String criteria, String value) {
		AnalogRadioBroadcasts analogRadioBroadcasts = new AnalogRadioBroadcasts();
		analogRadioBroadcasts = radioBroadcastDAO.viewRadioBroadcastsAnalog(criteria, value);
		return analogRadioBroadcasts;
	}

	public AnalogRadioBroadcast getThisBroadcastAnalog(long broadcastId) {
		AnalogRadioBroadcast analogRadioBroadcast = new AnalogRadioBroadcast();
		analogRadioBroadcast = radioBroadcastDAO.getThisBroadcastAnalog(broadcastId);
		return analogRadioBroadcast;
	}

	public int updateRadioBroadcastAnalog(AnalogRadioBroadcast analogRadioBroadcast, long broadcastId) {
		int result = radioBroadcastDAO.updateRadioBroadcastAnalog(analogRadioBroadcast, broadcastId);
		return result;
	}
}
